package de.fstyle.android.location;

import de.fstyle.android.location.startstop.AbstractStartStopActivity;
import de.fstyle.android.location.util.DefaultLocationListener;
import android.location.Location;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;

public class UpdateLocationListener extends DefaultLocationListener {

	public static final String LOG_TAG = "update_location";
	
	private AbstractStartStopActivity activity;
	private boolean running;
	
	public boolean isRunning() {
		return running;
	}
	
	public void setRunning(boolean running) {
		this.running = running;
	}

	public void setActivity(AbstractStartStopActivity activity) {
		this.activity = activity;
	}
	
	@Override
	public void onLocationChanged(final Location location) {
		Log.d(LOG_TAG, "updating location from " + location.getProvider());
		
		Handler handler = new Handler(Looper.getMainLooper());
		handler.post(new Runnable() {
			@Override
			public void run() {
				if (UpdateLocationListener.this.activity != null) {
					UpdateLocationListener.this.activity.add(location);
				}
			}
		});
	}
}
